package Text16;

import java.io.*;
import java.util.*;

public class Main {
    //    输入的第一行包含两个整数 n,m，分别表示计算机数目和要分配的任务数。
//    第二行包含 n个整数 v1,v2,···vn，分别表示每个计算机的运算能力。
//    接下来 m行每行 4个整数 ai,bi,ci,di，意义如上所述。数据保证 ai严格递增，即 ai<ai+1。
    static int N = 200010;
    static int[] s = new int[N];
    static PriorityQueue<Task> q[] = new PriorityQueue[N];

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s1=in.readLine().split(" ");
        int n = Integer.parseInt(s1[0]);
        int m = Integer.parseInt(s1[1]);
        String[] s2=in.readLine().split(" ");
        for (int i = 1; i <= n; i++) {
            s[i] = Integer.parseInt(s2[i-1]);
        }
        for (int i = 1; i <= n; i++) {
            q[i] = new PriorityQueue<>();
        }
        while (m-- > 0) {
            String[] s3=in.readLine().split(" ");
            int a = Integer.parseInt(s3[0]);
            int b = Integer.parseInt(s3[1]);
            int c = Integer.parseInt(s3[2]);
            int d = Integer.parseInt(s3[3]);
            while (!q[b].isEmpty() && q[b].peek().x <= a) {
                s[b] += q[b].poll().y;
            }
            if (s[b] < d) {
               out.write("-1\n");
            } else {
                q[b].offer(new Task(a + c, d));
                s[b] -= d;
                out.write(s[b]+"\n");
            }
            out.flush();
        }
    }
}

class Task implements Comparable<Task> {
    int x, y;

    public Task(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public int compareTo(Task o) {
        return Integer.compare(this.x, o.x);
    }
}